home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group03a.txt
/
000074_icon-group-sender_Tue Apr 15 12:26:33 2003.msg
< prev
next >
Wrap
Internet Message Format
|
2003-12-22
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id h3FJQFM11960
for icon-group-addresses; Tue, 15 Apr 2003 12:26:15 -0700 (MST)
Message-Id: <200304151926.h3FJQFM11960@baskerville.CS.Arizona.EDU>
From: "Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net>
X-Newsgroups: comp.lang.icon
Subject: Re: Simplifying Integer Arithmetic
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Date: Tue, 15 Apr 2003 15:18:01 GMT
X-Complaints-To: abuse@verizon.net
To: icon-group@cs.arizona.edu
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Perhaps there is a way to have the best of both worlds. We could add the
configuration parameter ROUNDS_TO_0 that will indicate whether C integer
division / modulo rounds to 0 on this platform. This macro can be used to
make sure that the more complicated versions of div3 / mod3 are used only
when necessary, as follows:
/*
* div3 - integer divide with overflow checking (always rounds to 0)
*/
word div3(a, b)
word a, b;
{
#if ROUNDS_TO_0
/* Simplified implementation, C result needs no adjusting */
#else
/* More complicated implementation, adjusts C result if necessary to get
rounding to 0 */
#endif
}
Within the file "src/h/config.h", we can guarantee that ROUNDS_TO_0 is
defined with the following preprocessor directives:
#ifndef ROUNDS_TO_0
#if ( 5 / (-3) == -1 ) && ( (-5) / 3 == -1 ) && ( (-5) / (-3) == 1 )
#define ROUNDS_TO_0 1
#else
#define ROUNDS_TO_0 0
#endif
#endif /* ROUNDS_TO_0 */
If there is some platform for which this does not set ROUNDS_TO_0 to the
appropriate value, you can set it in 'src/h/define.h'.